/**
 * Copyright (c) 2008 Luciano Bustos - riaevolution.com, All Rights Reserved.
 * 
 * Contact luchyx@riaevolution.com
 * See www.riaevolution.com
 *  
 * Permission is hereby granted, free of charge, to any person obtaining a copy of 
 * this software and associated documentation files (the "Software"), to deal in 
 * the Software without restriction, including without limitation the rights to
 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
 * of the Software, and to permit persons to whom the Software is furnished to do
 * so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in all 
 * copies or substantial portions of the Software.
 * 
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE. 
 * */
package com.riaevolution.components
{
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	import mx.core.UIComponent;
	/**
	 * A small divider indicator that display our current status on a colapsible form.
	 * 
	 * 
	 * 
	 **/
	public class DividerIndicator extends UIComponent
	{
		public function DividerIndicator()
		{
			super();
			addEventListener(MouseEvent.MOUSE_OVER, turnOn);
			addEventListener(MouseEvent.MOUSE_OUT, turnOn);
		}
		
		private static var arrowSize:int = 5;
		
		private var isOn:Boolean = false;
		
		public var dividerColor:int = 0xFF0000;
		/**
		 * highligth handler. 
		 * @param event
		 * 
		 */		
		private function turnOn(event:Event):void {
			isOn = (event.type == MouseEvent.MOUSE_OVER);
			invalidateDisplayList();
		}
		
		override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void {
			super.updateDisplayList(unscaledWidth,unscaledHeight);
			
			var col:int = Number(this.getStyle('color'));
			if( col != 0) {
				dividerColor = col;
			}
			
			this.graphics.clear();
			this.graphics.beginFill(dividerColor, isOn ? 1 : .5);			
			this.graphics.drawRect(0,0,unscaledWidth, 3);
			this.graphics.endFill();
			
			this.graphics.beginFill(dividerColor, isOn ? 1 : .5);
			this.graphics.moveTo(unscaledWidth/2 - arrowSize,0);
			
			this.graphics.lineTo(unscaledWidth/2 + arrowSize,0);
			this.graphics.lineTo(unscaledWidth/2 , _toogle ?  -arrowSize : arrowSize);
			this.graphics.lineTo(unscaledWidth/2 - arrowSize,0);
			this.graphics.endFill();
		}
		
		private var _toogle:Boolean = false;
		[Bindable]
		/**
		 * Toogle the arrow indicator element.
		 *  
		 * @param value Booleano
		 */		
		public function set toogle(value:Boolean):void {
			_toogle = value;
		}
		public function get toogle():Boolean {
			return _toogle;
		}
		
	}
}